package demo8;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.Connection;


public class DBUtil implements InitializingBean {
    private DruidDataSource dataSource;
    public DBUtil(DruidDataSource dataSource){
        this.dataSource = dataSource;
    }
    @Override
    public void afterPropertiesSet() throws Exception{
        System.out.println("=== DataSource 初始化信息 ===");
        System.out.println("URL: " + dataSource.getUrl());
        System.out.println("Username: " + dataSource.getUsername());
        System.out.println("Password: " + dataSource.getPassword());
        System.out.println("============================");
    }
    public Connection getConnection() throws Exception
    {
        return dataSource.getConnection();
    }

}
